

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

    <title>saml2.metadata &mdash; SAML Python library classes and methods</title>

    <link rel="stylesheet" href="../../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />

    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../',
        VERSION:     '',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../_static/doctools.js"></script>
    <link rel="top" title="SAML Python library classes and methods" href="../../index.html" />
    <link rel="up" title="Class code" href="../index.html" />
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Class Index"
             >modules</a> |</li>
        <li><a href="../../index.html">SAML Python library classes and methods</a> &raquo;</li>
          <li><a href="../index.html" accesskey="U">Class code</a> &raquo;</li>
      </ul>
    </div>

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">

  <h1>Source code for saml2.metadata</h1><div class="highlight"><pre>
<span class="c"># -*- coding: utf-8 -*-</span>


<span class="kn">from</span> <span class="nn">time</span> <span class="kn">import</span> <span class="n">gmtime</span><span class="p">,</span> <span class="n">strftime</span>
<span class="kn">from</span> <span class="nn">datetime</span> <span class="kn">import</span> <span class="n">datetime</span>
<span class="kn">from</span> <span class="nn">xml.dom.minidom</span> <span class="kn">import</span> <span class="n">parseString</span>

<span class="kn">from</span> <span class="nn">saml2.constants</span> <span class="kn">import</span> <span class="n">OneLogin_Saml2_Constants</span>
<span class="kn">from</span> <span class="nn">saml2.utils</span> <span class="kn">import</span> <span class="n">OneLogin_Saml2_Utils</span>


<div class="viewcode-block" id="OneLogin_Saml2_Metadata"><a class="viewcode-back" href="../../saml2.html#saml2.metadata.OneLogin_Saml2_Metadata">[docs]</a><span class="k">class</span> <span class="nc">OneLogin_Saml2_Metadata</span><span class="p">:</span>

    <span class="n">TIME_VALID</span> <span class="o">=</span> <span class="mi">172800</span>   <span class="c"># 2 days</span>
    <span class="n">TIME_CACHED</span> <span class="o">=</span> <span class="mi">604800</span>  <span class="c"># 1 week</span>

    <span class="nd">@staticmethod</span>
<div class="viewcode-block" id="OneLogin_Saml2_Metadata.builder"><a class="viewcode-back" href="../../saml2.html#saml2.metadata.OneLogin_Saml2_Metadata.builder">[docs]</a>    <span class="k">def</span> <span class="nf">builder</span><span class="p">(</span><span class="n">sp</span><span class="p">,</span> <span class="n">authnsign</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">wsign</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">valid_until</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">cache_duration</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">contacts</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">organization</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Build the metadata of the SP</span>

<span class="sd">        :param sp: The SP data</span>
<span class="sd">        :type sp: string</span>

<span class="sd">        :param authnsign: authnRequestsSigned attribute</span>
<span class="sd">        :type authnsign: string</span>

<span class="sd">        :param wsign: wantAssertionsSigned attribute</span>
<span class="sd">        :type wsign: string</span>

<span class="sd">        :param valid_until: Metadata&#39;s valid time</span>
<span class="sd">        :type valid_until: DateTime</span>

<span class="sd">        :param cache_duration: Duration of the cache in seconds</span>
<span class="sd">        :type cache_duration: Timestamp</span>

<span class="sd">        :param contacts: Contacts info</span>
<span class="sd">        :type contacts: dict</span>

<span class="sd">        :param organization: Organization ingo</span>
<span class="sd">        :type organization: dict</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">valid_until</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
            <span class="n">valid_until</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">datetime</span><span class="o">.</span><span class="n">now</span><span class="p">()</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="s">&quot;</span><span class="si">%s</span><span class="s">&quot;</span><span class="p">))</span> <span class="o">+</span> <span class="n">OneLogin_Saml2_Metadata</span><span class="o">.</span><span class="n">TIME_VALID</span>
        <span class="n">valid_until_time</span> <span class="o">=</span> <span class="n">gmtime</span><span class="p">(</span><span class="n">valid_until</span><span class="p">)</span>
        <span class="n">valid_until_time</span> <span class="o">=</span> <span class="n">strftime</span><span class="p">(</span><span class="s">r&#39;%Y-%m-</span><span class="si">%d</span><span class="s">T%H:%M:%SZ&#39;</span><span class="p">,</span> <span class="n">valid_until_time</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">cache_duration</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
            <span class="n">cache_duration</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">datetime</span><span class="o">.</span><span class="n">now</span><span class="p">()</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="s">&quot;</span><span class="si">%s</span><span class="s">&quot;</span><span class="p">))</span> <span class="o">+</span> <span class="n">OneLogin_Saml2_Metadata</span><span class="o">.</span><span class="n">TIME_CACHED</span>
        <span class="k">if</span> <span class="n">contacts</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
            <span class="n">contacts</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">if</span> <span class="n">organization</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
            <span class="n">organization</span> <span class="o">=</span> <span class="p">{}</span>

        <span class="n">sls</span> <span class="o">=</span> <span class="s">&#39;&#39;</span>
        <span class="k">if</span> <span class="s">&#39;singleLogoutService&#39;</span> <span class="ow">in</span> <span class="n">sp</span><span class="p">:</span>
            <span class="n">sls</span> <span class="o">=</span> <span class="s">&quot;&quot;&quot;&lt;md:SingleLogoutService Binding=&quot;</span><span class="si">%(binding)s</span><span class="s">&quot;</span>
<span class="s">                                Location=&quot;</span><span class="si">%(location)s</span><span class="s">&quot; /&gt;&quot;&quot;&quot;</span> <span class="o">%</span> <span class="p">{</span>
                <span class="s">&#39;binding&#39;</span><span class="p">:</span> <span class="n">sp</span><span class="p">[</span><span class="s">&#39;singleLogoutService&#39;</span><span class="p">][</span><span class="s">&#39;binding&#39;</span><span class="p">],</span>
                <span class="s">&#39;location&#39;</span><span class="p">:</span> <span class="n">sp</span><span class="p">[</span><span class="s">&#39;singleLogoutService&#39;</span><span class="p">][</span><span class="s">&#39;url&#39;</span><span class="p">],</span>
            <span class="p">}</span>

        <span class="n">str_authnsign</span> <span class="o">=</span> <span class="s">&#39;true&#39;</span> <span class="k">if</span> <span class="n">authnsign</span> <span class="k">else</span> <span class="s">&#39;false&#39;</span>
        <span class="n">str_wsign</span> <span class="o">=</span> <span class="s">&#39;true&#39;</span> <span class="k">if</span> <span class="n">wsign</span> <span class="k">else</span> <span class="s">&#39;false&#39;</span>

        <span class="n">str_organization</span> <span class="o">=</span> <span class="s">&#39;&#39;</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">organization</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
            <span class="n">organization_info</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="k">for</span> <span class="p">(</span><span class="n">lang</span><span class="p">,</span> <span class="n">info</span><span class="p">)</span> <span class="ow">in</span> <span class="n">organization</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
                <span class="n">organization_info</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">&quot;&quot;&quot;    &lt;md:Organization&gt;</span>
<span class="s">        &lt;md:OrganizationName xml:lang=&quot;</span><span class="si">%(lang)s</span><span class="s">&quot;&gt;</span><span class="si">%(name)s</span><span class="s">&lt;/md:OrganizationName&gt;</span>
<span class="s">        &lt;md:OrganizationDisplayName xml:lang=&quot;</span><span class="si">%(lang)s</span><span class="s">&quot;&gt;</span><span class="si">%(display_name)s</span><span class="s">&lt;/md:OrganizationDisplayName&gt;</span>
<span class="s">        &lt;md:OrganizationURL xml:lang=&quot;</span><span class="si">%(lang)s</span><span class="s">&quot;&gt;</span><span class="si">%(url)s</span><span class="s">&lt;/md:OrganizationURL&gt;</span>
<span class="s">    &lt;/md:Organization&gt;&quot;&quot;&quot;</span> <span class="o">%</span> <span class="p">{</span>
                    <span class="s">&#39;lang&#39;</span><span class="p">:</span> <span class="n">lang</span><span class="p">,</span>
                    <span class="s">&#39;name&#39;</span><span class="p">:</span> <span class="n">info</span><span class="p">[</span><span class="s">&#39;name&#39;</span><span class="p">],</span>
                    <span class="s">&#39;display_name&#39;</span><span class="p">:</span> <span class="n">info</span><span class="p">[</span><span class="s">&#39;displayname&#39;</span><span class="p">],</span>
                    <span class="s">&#39;url&#39;</span><span class="p">:</span> <span class="n">info</span><span class="p">[</span><span class="s">&#39;url&#39;</span><span class="p">],</span>
                <span class="p">})</span>
            <span class="n">str_organization</span> <span class="o">=</span> <span class="s">&#39;</span><span class="se">\n</span><span class="s">&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">organization_info</span><span class="p">)</span>

        <span class="n">str_contacts</span> <span class="o">=</span> <span class="s">&#39;&#39;</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">contacts</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
            <span class="n">contacts_info</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="k">for</span> <span class="p">(</span><span class="n">ctype</span><span class="p">,</span> <span class="n">info</span><span class="p">)</span> <span class="ow">in</span> <span class="n">contacts</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
                <span class="n">contacts_info</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">&quot;&quot;&quot;    &lt;md:ContactPerson contactType=&quot;</span><span class="si">%(type)s</span><span class="s">&quot;&gt;</span>
<span class="s">        &lt;md:GivenName&gt;</span><span class="si">%(name)s</span><span class="s">&lt;/md:GivenName&gt;</span>
<span class="s">        &lt;md:EmailAddress&gt;</span><span class="si">%(email)s</span><span class="s">&lt;/md:EmailAddress&gt;</span>
<span class="s">    &lt;/md:ContactPerson&gt;&quot;&quot;&quot;</span> <span class="o">%</span> <span class="p">{</span>
                    <span class="s">&#39;type&#39;</span><span class="p">:</span> <span class="n">ctype</span><span class="p">,</span>
                    <span class="s">&#39;name&#39;</span><span class="p">:</span> <span class="n">info</span><span class="p">[</span><span class="s">&#39;givenName&#39;</span><span class="p">],</span>
                    <span class="s">&#39;email&#39;</span><span class="p">:</span> <span class="n">info</span><span class="p">[</span><span class="s">&#39;emailAddress&#39;</span><span class="p">],</span>
                <span class="p">})</span>
            <span class="n">str_contacts</span> <span class="o">=</span> <span class="s">&#39;</span><span class="se">\n</span><span class="s">&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">contacts_info</span><span class="p">)</span>

        <span class="n">metadata</span> <span class="o">=</span> <span class="s">&quot;&quot;&quot;&lt;?xml version=&quot;1.0&quot;?&gt;</span>
<span class="s">&lt;md:EntityDescriptor xmlns:md=&quot;urn:oasis:names:tc:SAML:2.0:metadata&quot;</span>
<span class="s">                     validUntil=&quot;</span><span class="si">%(valid)s</span><span class="s">&quot;</span>
<span class="s">                     cacheDuration=&quot;PT</span><span class="si">%(cache)s</span><span class="s">S&quot;</span>
<span class="s">                     entityID=&quot;</span><span class="si">%(entity_id)s</span><span class="s">&quot;&gt;</span>
<span class="s">    &lt;md:SPSSODescriptor AuthnRequestsSigned=&quot;</span><span class="si">%(authnsign)s</span><span class="s">&quot; WantAssertionsSigned=&quot;</span><span class="si">%(wsign)s</span><span class="s">&quot; protocolSupportEnumeration=&quot;urn:oasis:names:tc:SAML:2.0:protocol&quot;&gt;</span>
<span class="s">        &lt;md:NameIDFormat&gt;</span><span class="si">%(name_id_format)s</span><span class="s">&lt;/md:NameIDFormat&gt;</span>
<span class="s">        &lt;md:AssertionConsumerService Binding=&quot;</span><span class="si">%(binding)s</span><span class="s">&quot;</span>
<span class="s">                                     Location=&quot;</span><span class="si">%(location)s</span><span class="s">&quot;</span>
<span class="s">                                     index=&quot;1&quot; /&gt;</span>
<span class="si">%(sls)s</span><span class="s"></span>
<span class="s">    &lt;/md:SPSSODescriptor&gt;</span>
<span class="si">%(organization)s</span><span class="s"></span>
<span class="si">%(contacts)s</span><span class="s"></span>
<span class="s">&lt;/md:EntityDescriptor&gt;&quot;&quot;&quot;</span> <span class="o">%</span> <span class="p">{</span>
            <span class="s">&#39;valid&#39;</span><span class="p">:</span> <span class="n">valid_until_time</span><span class="p">,</span>
            <span class="s">&#39;cache&#39;</span><span class="p">:</span> <span class="n">cache_duration</span><span class="p">,</span>
            <span class="s">&#39;entity_id&#39;</span><span class="p">:</span> <span class="n">sp</span><span class="p">[</span><span class="s">&#39;entityId&#39;</span><span class="p">],</span>
            <span class="s">&#39;authnsign&#39;</span><span class="p">:</span> <span class="n">str_authnsign</span><span class="p">,</span>
            <span class="s">&#39;wsign&#39;</span><span class="p">:</span> <span class="n">str_wsign</span><span class="p">,</span>
            <span class="s">&#39;name_id_format&#39;</span><span class="p">:</span> <span class="n">sp</span><span class="p">[</span><span class="s">&#39;NameIDFormat&#39;</span><span class="p">],</span>
            <span class="s">&#39;binding&#39;</span><span class="p">:</span> <span class="n">sp</span><span class="p">[</span><span class="s">&#39;assertionConsumerService&#39;</span><span class="p">][</span><span class="s">&#39;binding&#39;</span><span class="p">],</span>
            <span class="s">&#39;location&#39;</span><span class="p">:</span> <span class="n">sp</span><span class="p">[</span><span class="s">&#39;assertionConsumerService&#39;</span><span class="p">][</span><span class="s">&#39;url&#39;</span><span class="p">],</span>
            <span class="s">&#39;sls&#39;</span><span class="p">:</span> <span class="n">sls</span><span class="p">,</span>
            <span class="s">&#39;organization&#39;</span><span class="p">:</span> <span class="n">str_organization</span><span class="p">,</span>
            <span class="s">&#39;contacts&#39;</span><span class="p">:</span> <span class="n">str_contacts</span><span class="p">,</span>
        <span class="p">}</span>

        <span class="k">return</span> <span class="n">metadata</span>
</div>
    <span class="nd">@staticmethod</span>
<div class="viewcode-block" id="OneLogin_Saml2_Metadata.sign_metadata"><a class="viewcode-back" href="../../saml2.html#saml2.metadata.OneLogin_Saml2_Metadata.sign_metadata">[docs]</a>    <span class="k">def</span> <span class="nf">sign_metadata</span><span class="p">(</span><span class="n">metadata</span><span class="p">,</span> <span class="n">key</span><span class="p">,</span> <span class="n">cert</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Sign the metadata with the key/cert provided</span>

<span class="sd">        :param metadata: SAML Metadata XML</span>
<span class="sd">        :type metadata: string</span>

<span class="sd">        :param key: x509 key</span>
<span class="sd">        :type key: string</span>

<span class="sd">        :param cert: x509 cert</span>
<span class="sd">        :type cert: string</span>

<span class="sd">        :returns: Signed Metadata</span>
<span class="sd">        :rtype: string</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="n">OneLogin_Saml2_Utils</span><span class="o">.</span><span class="n">add_sign</span><span class="p">(</span><span class="n">metadata</span><span class="p">,</span> <span class="n">key</span><span class="p">,</span> <span class="n">cert</span><span class="p">)</span>
</div>
    <span class="nd">@staticmethod</span>
<div class="viewcode-block" id="OneLogin_Saml2_Metadata.add_x509_key_descriptors"><a class="viewcode-back" href="../../saml2.html#saml2.metadata.OneLogin_Saml2_Metadata.add_x509_key_descriptors">[docs]</a>    <span class="k">def</span> <span class="nf">add_x509_key_descriptors</span><span class="p">(</span><span class="n">metadata</span><span class="p">,</span> <span class="n">cert</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Add the x509 descriptors (sign/encriptation to the metadata</span>
<span class="sd">        The same cert will be used for sign/encrypt</span>

<span class="sd">        :param metadata: SAML Metadata XML</span>
<span class="sd">        :type metadata: string</span>

<span class="sd">        :param cert: x509 cert</span>
<span class="sd">        :type cert: string</span>

<span class="sd">        :returns: Metadata with KeyDescriptors</span>
<span class="sd">        :rtype: string</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">xml</span> <span class="o">=</span> <span class="n">parseString</span><span class="p">(</span><span class="n">metadata</span><span class="p">)</span>
        <span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="s">&#39;Error parsing metadata. &#39;</span> <span class="o">+</span> <span class="n">e</span><span class="o">.</span><span class="n">message</span><span class="p">)</span>

        <span class="n">formated_cert</span> <span class="o">=</span> <span class="n">OneLogin_Saml2_Utils</span><span class="o">.</span><span class="n">format_cert</span><span class="p">(</span><span class="n">cert</span><span class="p">,</span> <span class="bp">False</span><span class="p">)</span>
        <span class="n">x509_certificate</span> <span class="o">=</span> <span class="n">xml</span><span class="o">.</span><span class="n">createElementNS</span><span class="p">(</span><span class="n">OneLogin_Saml2_Constants</span><span class="o">.</span><span class="n">NS_DS</span><span class="p">,</span> <span class="s">&#39;ds:X509Certificate&#39;</span><span class="p">)</span>
        <span class="n">content</span> <span class="o">=</span> <span class="n">xml</span><span class="o">.</span><span class="n">createTextNode</span><span class="p">(</span><span class="n">formated_cert</span><span class="p">)</span>
        <span class="n">x509_certificate</span><span class="o">.</span><span class="n">appendChild</span><span class="p">(</span><span class="n">content</span><span class="p">)</span>

        <span class="n">key_data</span> <span class="o">=</span> <span class="n">xml</span><span class="o">.</span><span class="n">createElementNS</span><span class="p">(</span><span class="n">OneLogin_Saml2_Constants</span><span class="o">.</span><span class="n">NS_DS</span><span class="p">,</span> <span class="s">&#39;ds:X509Data&#39;</span><span class="p">)</span>
        <span class="n">key_data</span><span class="o">.</span><span class="n">appendChild</span><span class="p">(</span><span class="n">x509_certificate</span><span class="p">)</span>

        <span class="n">key_info</span> <span class="o">=</span> <span class="n">xml</span><span class="o">.</span><span class="n">createElementNS</span><span class="p">(</span><span class="n">OneLogin_Saml2_Constants</span><span class="o">.</span><span class="n">NS_DS</span><span class="p">,</span> <span class="s">&#39;ds:KeyInfo&#39;</span><span class="p">)</span>
        <span class="n">key_info</span><span class="o">.</span><span class="n">appendChild</span><span class="p">(</span><span class="n">key_data</span><span class="p">)</span>

        <span class="n">key_descriptor</span> <span class="o">=</span> <span class="n">xml</span><span class="o">.</span><span class="n">createElementNS</span><span class="p">(</span><span class="n">OneLogin_Saml2_Constants</span><span class="o">.</span><span class="n">NS_DS</span><span class="p">,</span> <span class="s">&#39;md:KeyDescriptor&#39;</span><span class="p">)</span>

        <span class="n">entity_descriptor</span> <span class="o">=</span> <span class="n">sp_sso_descriptor</span> <span class="o">=</span> <span class="n">xml</span><span class="o">.</span><span class="n">getElementsByTagName</span><span class="p">(</span><span class="s">&#39;md:EntityDescriptor&#39;</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>
        <span class="n">entity_descriptor</span><span class="o">.</span><span class="n">setAttribute</span><span class="p">(</span><span class="s">&#39;xmlns:ds&#39;</span><span class="p">,</span> <span class="n">OneLogin_Saml2_Constants</span><span class="o">.</span><span class="n">NS_DS</span><span class="p">)</span>

        <span class="n">sp_sso_descriptor</span> <span class="o">=</span> <span class="n">xml</span><span class="o">.</span><span class="n">getElementsByTagName</span><span class="p">(</span><span class="s">&#39;md:SPSSODescriptor&#39;</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>
        <span class="n">sp_sso_descriptor</span><span class="o">.</span><span class="n">insertBefore</span><span class="p">(</span><span class="n">key_descriptor</span><span class="o">.</span><span class="n">cloneNode</span><span class="p">(</span><span class="bp">True</span><span class="p">),</span> <span class="n">sp_sso_descriptor</span><span class="o">.</span><span class="n">firstChild</span><span class="p">)</span>
        <span class="n">sp_sso_descriptor</span><span class="o">.</span><span class="n">insertBefore</span><span class="p">(</span><span class="n">key_descriptor</span><span class="o">.</span><span class="n">cloneNode</span><span class="p">(</span><span class="bp">True</span><span class="p">),</span> <span class="n">sp_sso_descriptor</span><span class="o">.</span><span class="n">firstChild</span><span class="p">)</span>

        <span class="n">signing</span> <span class="o">=</span> <span class="n">xml</span><span class="o">.</span><span class="n">getElementsByTagName</span><span class="p">(</span><span class="s">&#39;md:KeyDescriptor&#39;</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>
        <span class="n">signing</span><span class="o">.</span><span class="n">setAttribute</span><span class="p">(</span><span class="s">&#39;use&#39;</span><span class="p">,</span> <span class="s">&#39;signing&#39;</span><span class="p">)</span>

        <span class="n">encryption</span> <span class="o">=</span> <span class="n">xml</span><span class="o">.</span><span class="n">getElementsByTagName</span><span class="p">(</span><span class="s">&#39;md:KeyDescriptor&#39;</span><span class="p">)[</span><span class="mi">1</span><span class="p">]</span>
        <span class="n">encryption</span><span class="o">.</span><span class="n">setAttribute</span><span class="p">(</span><span class="s">&#39;use&#39;</span><span class="p">,</span> <span class="s">&#39;encryption&#39;</span><span class="p">)</span>

        <span class="n">signing</span><span class="o">.</span><span class="n">appendChild</span><span class="p">(</span><span class="n">key_info</span><span class="p">)</span>
        <span class="n">encryption</span><span class="o">.</span><span class="n">appendChild</span><span class="p">(</span><span class="n">key_info</span><span class="o">.</span><span class="n">cloneNode</span><span class="p">(</span><span class="bp">True</span><span class="p">))</span>

        <span class="k">return</span> <span class="n">xml</span><span class="o">.</span><span class="n">toxml</span><span class="p">()</span></div></div>
</pre></div>

          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="../../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Class Index"
             >modules</a> |</li>
        <li><a href="../../index.html">SAML Python library classes and methods</a> &raquo;</li>
          <li><a href="../index.html" >Class code</a> &raquo;</li>
      </ul>
    </div>
    <div class="footer">
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
    </div>
  </body>
</html>
